﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AzureBlogWebRole.widgets.Channels
{
    public partial class widget : WidgetBase 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Title = "Canaux Zecloud";
        }
        public override string Name
        {
            get { return "Channels"; }
        }

        public override bool IsEditable
        {
            get { return false; }
        }

        public override void LoadWidget()
        {
            // Nothing to load
        }

        protected void Literal1_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<AzureProvider.MiniSensor.Channel> chs;
                if (HttpRuntime.Cache["widget_channels"] == null)
                {
                AzureProvider.MiniSensor.Channels ch_get = new AzureProvider.MiniSensor.Channels();
                chs = ch_get.GetListChannels();
                }
                else
                {
                    chs = (List < AzureProvider.MiniSensor.Channel >)HttpRuntime.Cache["widget_channels"];
                }
                foreach (var item in chs)
                {
                    ((Literal)sender).Text += "<a href=\"\\channel.aspx?channelid=" + item.Id.ToString() + "\" >" + item.Name + "</a><br/>";
                }
            }
        }
    }
}